<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      >

    <body>

        <ui:composition template="./template.xhtml">

            <ui:define name="title">
                Event Page
            </ui:define>

            <ui:define name="content">
                <h2 class="art-postheader">Event
                </h2>
                <f:view>
                    <h:form id="frNotLogin">
                        <c:if test="${user == null}">
                            <h:outputText escape="false" value="(No Events Found)" rendered="#{eventController.items.rowCount == 0}"/>
                            <p:dataTable value="#{eventController.items}" var="item" rendered="#{eventController.items.rowCount>0}"
                                         paginator="true" rows="10"
                                         paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                         rowsPerPageTemplate="5,10,15"
                                         style="font-size: 12px;"
                                         >
                                <p:column sortBy="#{item.eventName}" filterBy="#{item.eventName}">
                                    <f:facet name="header">
                                        <h:outputText value="EventName"/>
                                    </f:facet>
                                    <h:outputText value="#{item.eventName}"/>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="Image"/>
                                    </f:facet>
                                    <p:graphicImage value="/resources/css/images/#{item.imageEvent}" height="80" width="50"/>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="EventTitle"/>
                                    </f:facet>
                                    <h:outputText value="#{item.eventTitle}"/>
                                </p:column>
                                <p:column sortBy="#{item.startEvent}">
                                    <f:facet name="header">
                                        <h:outputText value="StartEvent"/>
                                    </f:facet>
                                    <h:outputText value="#{item.startEvent}">
                                        <f:convertDateTime pattern="MM/dd/yyyy" />
                                    </h:outputText>
                                </p:column>
                                <p:column sortBy="#{item.finishEvent}">
                                    <f:facet name="header">
                                        <h:outputText value="FinishEvent"/>
                                    </f:facet>
                                    <h:outputText value="#{item.finishEvent}">
                                        <f:convertDateTime pattern="MM/dd/yyyy" />
                                    </h:outputText>
                                </p:column>
                                <p:column sortBy="#{item.startReg}">
                                    <f:facet name="header">
                                        <h:outputText value="StartReg"/>
                                    </f:facet>
                                    <h:outputText value="#{item.startReg}">
                                        <f:convertDateTime pattern="MM/dd/yyyy" />
                                    </h:outputText>
                                </p:column>
                                <p:column sortBy="#{item.endReg}">
                                    <f:facet name="header">
                                        <h:outputText value="EndReg"/>
                                    </f:facet>
                                    <h:outputText value="#{item.endReg}" >
                                        <f:convertDateTime pattern="MM/dd/yyyy" />
                                    </h:outputText>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="Action"/>
                                    </f:facet>
                                    <p:commandButton image="ui-icon ui-icon-search" action="#{eventController.prepareView}" title="View Details" ajax="false"/>
                                </p:column>
                            </p:dataTable>
                        </c:if>
                    </h:form>
                    <h:form id="frLogin">
                        <c:if test="${user != null}">

                            <c:set value="#{user.isAdmin}" var="role"/>
                            <c:if test="${role == true}">
                                <p:commandButton icon="ui-icon-plusthick" action="#{eventController.prepareCreate}" value="Create New Event" ajax="false"/>
                            </c:if>
                            <h:outputText escape="false" value="(No Events Found)" rendered="#{eventController.items.rowCount == 0}"/>
                            <p:dataTable value="#{eventController.items}" var="item" rendered="#{eventController.items.rowCount>0}"
                                         paginator="true" rows="10"
                                         paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                         rowsPerPageTemplate="5,10,15"
                                         style="font-size: 2px;"

                                         >
                                <p:column style="width: 200px;" sortBy="#{item.eventName}" filterBy="#{item.eventName}">
                                    <f:facet name="header">
                                        <h:outputText value="EventName "/>
                                    </f:facet>
                                    <h:commandLink id="lnk" action="#{eventController.prepareView}">
                                        <h:outputText value="#{item.eventName}" />
                                    </h:commandLink>
                                    <p:tooltip for="lnk">
                                        <center>
                                            <p:graphicImage value="/resources/css/images/#{item.imageEvent}" height="120" width="120"/>
                                            <br/><h:outputText value="#{item.eventTitle}" styleClass="art-postheader"/><br/>

                                        </center>
                                    </p:tooltip>
                                </p:column>
                                <p:column sortBy="#{item.startReg}">
                                    <f:facet name="header">
                                        <h:outputText value="Start Reg  "/>
                                    </f:facet>
                                    <h:outputText value="#{item.startReg}">
                                        <f:convertDateTime pattern="MM/dd/yyyy" />
                                    </h:outputText>
                                </p:column>
                                <p:column sortBy="#{item.endReg}">
                                    <f:facet name="header">
                                        <h:outputText value="End Reg  "/>
                                    </f:facet>
                                    <h:outputText value="#{item.endReg}" >
                                        <f:convertDateTime pattern="MM/dd/yyyy" />
                                    </h:outputText>
                                </p:column>

                                <c:if test="${role == true}">
                                    <p:column sortBy="#{item.isDelete}" >
                                        <f:facet name="header">
                                            <h:outputText value="De-activate  "/>
                                            <h:outputText value=" "/>
                                        </f:facet>
                                        <p:selectBooleanCheckbox value="#{item.isDelete}" disabled="true" />
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Action"/>
                                        </f:facet>


                                        <p:commandButton image="ui-icon ui-icon-search" action="#{eventController.prepareView}" title="View Details" ajax="false"/>
                                        <p:commandButton image="ui-icon ui-icon-pencil" action="#{eventController.prepareEdit}" title="Edit" ajax="false" rendered="#{!eventController.checkControlEvent(item)}"/>
                                        <p:commandButton image="ui-icon ui-icon-close"
                                                         title="De-Activate"
                                                         ajax="false"
                                                         rendered="#{!item.isDelete}"
                                                         action="#{eventController.delete}"

                                                         />
                                        <p:commandButton image="ui-icon-check"
                                                         title="Re-Activate"
                                                         ajax="false"
                                                         rendered="#{item.isDelete}"
                                                         action="#{eventController.restore}"

                                                         />

                                    </p:column>

                                </c:if>
                                <c:if test="${role == false}">
                                    <p:column>
                                        <p:commandButton image="ui-icon ui-icon-check" action="#{registrationController.TakeIn(item)}"
                                                         title="Send request participate" ajax="false"
                                                         rendered="#{registrationController.checkTakeIn(item) and item.startReg.before(registrationController.today) and item.endReg.after(registrationController.today)}"/>
                                        <h:outputText value="End registration event !" rendered="#{item.endReg &lt; eventController.today and registrationController.checkTakeIn(item)}" style="font-style: oblique;color: red"/>
                                        <h:outputText value="Status: #{registrationController.reg.statusReg}"
                                                      rendered="#{!registrationController.checkTakeIn(item)}"
                                                      style="font-style: oblique;color: blue"/>
                                        <h:outputText value="Upcomming Registration !"
                                                      rendered="#{item.startReg.after(registrationController.today)}"
                                                      style="font-style: oblique;color: magenta"/>
                                    </p:column>
                                </c:if>

                            </p:dataTable>
                        </c:if>

                    </h:form>
                </f:view>

            </ui:define>

        </ui:composition>

    </body>

</html>
